package com.hongsheng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hongsheng.mapper.DepositoryMapper;
import com.hongsheng.pojo.Depository;
import com.hongsheng.service.DepositoryService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author admin
 * @version 1.0
 * @date 2023/8/11 16:23
 */
@Service
public class DepositoryServiceImpl implements DepositoryService {
    @Resource
    private DepositoryMapper depositoryMapper;
    //查询所有仓库
    @Override
    public List<Depository> findAllDepository() {
        return depositoryMapper.selectList(null);
    }
    //添加仓库
    @Override
    public Boolean insertDepository(Depository repository) {
        return depositoryMapper.insert(repository)>0;
    }
    //删除仓库
    @Override
    public Boolean deleteDepository(Integer id) {
        return depositoryMapper.deleteById(id)>0;
    }
    //编辑仓库
    @Override
    public Boolean updateDepository(Depository repository) {
       return depositoryMapper.updateById(repository)>0;
    }
    //根据id查询仓库
    @Override
    public Depository selectDepositoryById(Integer id) {
        return depositoryMapper.selectById(id);
    }

    @Override
    public IPage<Depository> getPage(Integer currentPage, Integer pageSize,Depository queryDepository) {
        IPage page = new Page(currentPage,pageSize);
        LambdaQueryWrapper<Depository> lqw = new LambdaQueryWrapper<Depository>();
        lqw.like(Strings.isNotEmpty(queryDepository.getName()),Depository::getName,queryDepository.getName());
        lqw.like(Strings.isNotEmpty(queryDepository.getType()),Depository::getType,queryDepository.getType());
        lqw.like(Strings.isNotEmpty(queryDepository.getManager()),
                Depository::getManager,queryDepository.getManager());
        return depositoryMapper.selectPage(page,lqw);
    }

    @Override
    public Boolean existGoods(Integer id) {
        Integer integer = depositoryMapper.existGoods(id);
        if (integer != null){
            return false;
        }
        return true;
    }
    @Override
    public Boolean findPhone(String driverPhone) {
        Boolean phone = depositoryMapper.findPhone(driverPhone);
        if (phone==null){
            return true;
        }else {
            return false;
        }
    }

}
